home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 546 < prev    next >
Encoding:
Text File  |  1996-08-06  |  6.5 KB  |  133 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: JdeBP@jba.co.uk (Jonathan de Boyne Pollard)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Portability. Modules. WAS: RE:  Are all Windows programs
  5. Date: 26 Feb 1996 09:38:30 PST
  6. Organization: JBA Software Products, Studley, England.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4grupq$6r4@silver.jba.co.uk>
  9. References: <UPMAIL04.199602192354270852@msn.com>
  10. Reply-To: JdeBP@donor2.demon.co.uk
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 26 Feb 1996 09:33:46 -0000
  13. X-Newsreader: TIN [version 1.2 PL2]
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBVAwUBMTHwLEy4NqrwXLNJAQGKZQH+JcYcQeORX+wuR97An20vxAlMEdevnRHz
  16.     IipJbht6mpKPjX5UxI4yD2AW9Co3+OE/70+3AsoBZAIbnU74H0Vujg==
  17.     =dGRX
  18. Originator: austern@isolde.mti.sgi.com
  19.  
  20. Eugene Lazutkin (INT@msn.com) wrote:
  21. | On     Tuesday, February 13, 1996 9:51 AM,     JdeBP@jba.co.uk 
  22. |     (Jonathan de Boyne Pollard) wrote:
  23. | > Again, this is not in fact true, and part of the problem that the original
  24. | > poster was pointing out.  The startup code in most Windows compilers calls
  25. | > WinMain directly.  There is no `main' function anywhere in the program at
  26. | > all.
  27. |
  28. | I don't care about the actual implementation.  Virtually there is a main().
  29.  
  30. Wrong.  There is *no* `main', and this is the problem.
  31.  
  32. | Almost all platforms call some stub before your main().
  33.  
  34. Again, this is not true.  `main' doesn't even have to be a function at all.
  35. All that is demanded is that the start of the program, *as it appears to the
  36. programmer in the C++ language source*, is a function called `main'.  The 
  37. implementation is perfectly free to recognise a definition of the `main'
  38. function, and to do whatever is necessary to ensure that the program
  39. "starts" with that function.
  40.  
  41. For instance, instead of emitting a symbol definition and a function
  42. prologue into the object file, the a C++ implementation is free to emit the
  43. C++ runtime initialisation code in place of a function prologue, and have 
  44. it fall through directly into the body of `main'.  As long as `return', the 
  45. arguments to `main', and exception processing appear just as they should 
  46. for a real function, the implementation is free to do as it wishes.
  47.  
  48. | > | BTW, the same can be applied to the Unix (MacOS) platform.  X-based
  49. | > | (Motif-based, Fresco-based,...) program are not portable either unless
  50. | > | you have the specific GUI implementation for your target platforms.
  51. | > 
  52. | > Not so.  If we are expanding the discussion to other platforms, you will
  53. | > find that many other platforms do not demand that programs be ill-formed 
  54. | > (as a program lacking any definition of `main' surely is).
  55. |
  56. | You can call a main() from the WinMain().
  57.  
  58. But you cannot compile
  59.  
  60. int main ( int, char ** ) { return 0 ; }
  61.  
  62. .  Again, you are not quite getting it.  If the implementation *requires* 
  63. you to define a `WinMain', and makes `main' optional then this is the 
  64. reverse of the language definition, where `main' is required and `LibMain' 
  65. (and indeed any other function) is optional.
  66.  
  67. | > I don't remember about X offhand, but OS/2 Presentation Manager does not
  68. | > require non-standard startup procedures.  The PM API is, as far as the
  69. | > applications programmer is concerned, just another function library in a
  70. | > DLL, and OS/2 PM programs start with `int main(int, char **)' just the same
  71. | > as text-mode programs do.
  72. |
  73. | I still think that PM API makes programs unportable.
  74.  
  75. Try reading the next pert of my original message :
  76.  
  77. | > And *this* is the issue at hand, not whether the APIs are portable.  Most
  78. | > APIs appear as "just another function library" to the applications
  79. | > programmer, and portability or otherwise of libraries is not an issue with
  80. | > the C++ language itself.  The issue with the C++ language is that `main' is
  81. | > the defined start procedure of *any* C++ program (sauf constructors of
  82. | > objects at global namespace scope with static storage duration), and
  83. | > Windows programs are *forced* to *not* use `main'.
  84. |
  85. | IMHO, C++ language doesn't care about the name of functions.  
  86.  
  87. Well in this case YHO is wrong.  The C++ standard is specific about one
  88. particular function, denoted `main'.
  89.  
  90. | > Of course, as I've said before, the simple solution is to fix
  91. | > [basic.start.main] to allow
  92. | > 
  93. | >     int main ( HINSTANCE, HINSTANCE, char *, int ) { /*...*/ }
  94. | > 
  95. | > as a legal definition of `main' (my proposal is for the implementation to
  96. | > define a set of legal function types for the definition of `main', which at
  97. | > minimum must contain `int main()' and `int main(int, char**)').  Then 
  98. | > compiler vendors targetting DOS+Windows who wish to claim conformance can do
  99. | > so by allowing their compilers to recognise the above function definition.
  100. |
  101. | I'm not a pro in a standardization, but I think that this solution
  102. | looks like a patch for MS Windows(TM).  What if totally graphical
  103. | environment doesn't support any parameters or these parameters aren't a
  104. | text?  This is a Unix heritage (and useful one :-) ).  What does
  105. | HINSTANCE mean for ABCDOS?  What if all this four parameters don't make
  106. | any sense at all for particular OS?  E.g., Win32 doesn't use the second
  107. | HINSTANCE.  I don't speak about future OSes.
  108.  
  109. You didn't read the whole paragraph.  Read it again.  My proposal is that
  110. implementations can define a set of legal function types that they will
  111. accept in a program for the definition of `main', with the one restriction
  112. that `int main()' and `int main(int, char **)' be members of that set.
  113.  
  114. This allows Windows implementations to state that (in addition to the
  115. compulsory two definitions) they will accept a definition of `main' as 
  116. given above, and other implementations with similar requirements to allow
  117. whatever function definition of `main' makes their environment happy also.
  118.  
  119. This is known as meeting the problem halfway.  Currently, the C++ (draft)
  120. standard is both self-contraditory and restricted to UNIX-lookalike startup
  121. semantics.  Currently, Windows C++ implementations would not conform to the
  122. standard (were the drafts as they stand made into a standard).  If Windows 
  123. C++ implementations switch to using `main', and if the C++ standard is 
  124. modified (and corrected) as I've suggested, then Windows (and other) C++ 
  125. implementations will be able to conform in this area.
  126. ---
  127. [ To submit articles: Try just posting with your newsreader.  If that fails,
  128.                       use mailto:std-c++@ncar.ucar.edu
  129.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  130.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  131.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  132. ]
  133.